<!doctype html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>

    <body>
        <button onclick="addOneDebounce(1)">加一</button>
        <script>
            function debounce(fn, wait) {
                let timer = null
                return (...args) => {
                    if (timer) {
                        clearTimeout(timer)
                        timer = null
                    }
                    timer = setTimeout(() => {
                        fn.apply(this, args)
                    }, wait)
                }
            }
            let count = 0
            const addOne = function () {
                count++
                console.log(count)
            }
            const addOneDebounce = debounce(addOne, 500)
        </script>
    </body>
</html>
